package udp;

import java.io.IOException;
import java.net.*;

/**
 * 模拟创建一个UDP请求并发送数据出去
 * @author microdsyKoal
 * @date 2018年7月3日
 */
public class UdpSend {
    public static void main(String[] args) throws IOException {
        //1.创建udp服务。通过DatagramSocket对象。
        DatagramSocket ds = new DatagramSocket(8888);

        //2.确定数据。并封装成数据包。
        String src = "";
        //NJ日志
        //中间件 通过
        src = "Reg_ID=\"koalmiddle\" SN=\"ad6ca5359cf6482a\" User_Name=\"test2017051702\" User_ID=\"201705170200000000\" Organization_ID=\"32010000\" Operate_Time=\"2018-01-22 14:10:13\" Terminal_ID=\"192.168.10.182\" Operate_Type=\"0\" Operate_Result=\"1\" Error_Code=\"\" Fail_Reason=\"\" Version=\"KOAL_MID_JAVA_5.0\"";
        //中间价验证失败的日志:
        src = "Reg_ID=\"koalmiddle\" SN=\"ad6ca5359cf6482a\" User_Name=\"test2017051702\" User_ID=\"201705170200000000\" Organization_ID=\"32010000\" Operate_Time=\"2018-01-22 14:10:13\" Terminal_ID=\"192.168.10.182\" Operate_Type=\"0\" Operate_Result=\"0\" Error_Code=\"3000\" Fail_Reason=\"证书链验证未通过\" Version=\"KOAL_MID_JAVA_5.0\"";
        //安全认证网关5.2.4
        src = "session_id=\"0972230F44BD3D8A23960A3DDE9796B017CA6B3103DBD409917CA7F30FB33B0A\" Reg_ID=\"ssl524\" SSL-HRP DATE=\"2018-04-25 16:26:12\" CN=\"张三 123456789012345678\" SN=\"288053F34A275E184BB3601EBC27CE9F\" ST=\"32\" L=\"05\" L1=\"00\" O=\"22\" OU=\"06\" OU1=\"00\" ip=\"50.18.109.173\" url=\"http://10.32.201.66:11080/script/app\" result=\"未修改，无须下载\" Version=\"KOAL_SSL_Sp4\"";
        src = "session_id=\"1972230F44BD3D8A23960A3DDE9796B017CA6B3103DBD409917CA7F30FB33B0A\" Reg_ID=\"ssl524\" SSL-HRP DATE=\"2018-04-26 16:26:12\" CN=\"张金龙 123456789012345678\" SN=\"288053F34A275E184BB3601EBC27CE9F\" ST=\"32\" L=\"05\" L1=\"00\" O=\"22\" OU=\"06\" OU1=\"00\" ip=\"50.18.109.173\" url=\"http://10.32.201.66:11080/script/app\" result=\"未修改，无须下载\" Version=\"KOAL_SSL_Sp4\"";
        //交管旁路网关
        src = "AuthLog[2659]: DATE=\"2017/11/23 08:32:58\" User_Name=\"张甲\" User_ID=\"120111777506261025\" APPID=\"sslSSO\" GATE_IP=\"10.88.5.201\" CLIENT_IP=\"10.88.99.216\" CERT_SERIAL=\"571C6A453DED7E22386C60B1C880B0BC\" Organization_ID=\"120000061209\" Operate_Type=\"证书认证\" Operate_Result=\"成功\" Error_Code=\"\"  Version=\"KOAL_SSL_SSO\"";


        // 中航日志
        //RA操作日志
        src = "<14>date=\"2018-03-27 17:28:56\" operationid=\"reapply_accept\" actiontype=\"execute\" operator=\"C=CN,O=koal,OU=koal,E=RABusiOper@koal.com,CN=RABusiOper\" userdn=\"O=格尔软件,E=ktu3@koal.com,CN=ktu3\" result=\"true\" errormsg=\"null\" senderip=\"null\"";

        //CA操作日志
//        src = "<14>time=\"2018-03-27 15:38:06\" system=\"CAAdmin\" operator=\" \" oper_action=\"写日志配置\" oper_object=\"写日志配置\" result=\"0\" result_msg=\"成功\"";
        //CA服务日志
        src = "<14>time=\"2018-03-27 17:29:07\" system=\"CertService\" service_asker=\"www.koalra.com\" service_type=\"证书更新服务\" subject=\"CN=ktu3, E=ktu3@koal.com, O=格尔软件\" result=\"0\" result_msg=\"success\" issuer=\"CA_RSA\" senderip=\" \"";

        //KM日志
        src = "<14>timedone=2018-3-27 15:36:58;admin=KMBusiOper;op=更新日志配置;obj=logfilename=D:\\CA6.6.0\\SYT0901-KOALKM\\kmc.log, logFileMaxSize=10000KB, logFileMaxIndex=5, syslogHost=192.168.136.1, syslogFileOut=true, syslogConsoleOut=true, sysloglevel=一般, servicelogFileOut=true, servicelogConsoleOut=true, serviceloglevel=调试;result=成功 time=\"2018-03-27 15:36:58\"";
        //KM服务日志
        src = "<14>CA_ID=100, CLIENT_IP='127.0.0.1', ACTION='密钥分发', DESC='完成密钥分发,KeyIndex=G/EXPQ4RYqwizvhrjtaA3M4+qBQ=', encSN='26892554857327426002406262019', RESULT='成功' time=\"2018-03-30 15:41:42\"";


        //杜升林操作日志
        //<14>date="2018-12-11 17:28:56" operationid="cfgINFOSave" actiontype="execute" operator="C=CN,O=AECC,OU=东安,E=www@koal.com,CN=oper_RA" userdn="null" result="true" errormsg=\"null\" senderip=\"172.16.102.104\"
        src = "<14>date=\"2018-12-11 17:29:56\" operationid=\"cfgINFOSave\" actiontype=\"execute\" operator=\"C=CN,O=AECC,OU=东安,E=www@koal.com,CN=oper_RA\" userdn=\"null\" result=\"true\" errormsg=\"null\" senderip=\"172.16.102.104\"";

//        src = "PID=\"4501\" DATE=\"2018-12-11 17:29:56\" CN=\"测试证书test1\" GN=\"-\" O=\"组织test1\" OU=\"机构test1\" L=\"上海市\" ST=\"上海\" ip=\"192.168.220.10\" url=\"http://192.168.30.42:8080/favicon\" result=\"成功\" downflow=\"21630\" upflow=\"0\" duration=\"8\" ";
        
        int sendMax = 1;
        for (int i = 0; i < sendMax; i++) {
            byte[] buf = src.getBytes();//将一个字符串转化为一个字节数组
            DatagramPacket dp =
                    new DatagramPacket(buf, buf.length, InetAddress.getByName("127.0.0.1"), 514);

            //3.通过socket服务，将已有的数据包发送出去，通过send方法。
            ds.send(dp);
        }

        //4.关闭资源。
        ds.close();

    }
}
